/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ui.admin;

import hibernate.dao.LoginDAO;
import hibernate.dao.RoleDAO;
import hibernate.dao.StudentDAO;
import hibernate.entity.Login;
import hibernate.entity.Student;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import util.RandomGenerator;

/**
 *
 * @author NDH
 */
@ManagedBean
@RequestScoped
public class StudentManager extends AbstractAdminBean {

    private int STU_ROLE_ID = 3;

    /**
     * Creates a new instance of StudentManager
     */
    public StudentManager() {
    }
    List<Student> listStudent;
    StudentDAO sdao = new StudentDAO();
    LoginDAO lgDao = new LoginDAO();
    String name;
    String phone;
    String email;

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
    String username;
    String birthday;
    Student currStudent = new Student();

    public String getBirthday() {
        return birthday;
    }

    public void setBirthday(String birthday) {
        this.birthday = birthday;
    }

    public List<Student> getListStudent() {
        listStudent = sdao.readAll();
        return listStudent;
    }

    public void setListStudent(List<Student> listStudent) {
        this.listStudent = listStudent;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public Student getCurrStudent() {
        return currStudent;
    }

    public void setCurrStudent(Student currStudent) {
        this.currStudent = currStudent;
    }

    public String delete(Student s) {
        try {
            sdao.delete(s);
        } catch (Exception e) {
        }
        return "list";
    }

    public String edit(Student s) {
        currStudent = s;
        return "edit";
    }

   

//    public String docreate() {
//        RoleDAO rDao = new RoleDAO();
//            String random = RandomGenerator.randomString();
//            Login lg = new Login(username, random, rDao.getRoleByName("student"));
//            try {
//                if (lgDao.create(lg) > 0) {
//                    
//                    currStudent.setLogin(lg);
//                    currStudent.setLoginId(lg.getAccId());
//                    if (sdao.create(currStudent) > 0) {
//                       
//                    } else {
//                    }
//                }
//
//            } catch (Exception e) {
//            }
//            return "list";
////        }
////        return null;
//
//    }

    public String doupdate() {
        try {
            if (sdao.update(currStudent) > 0) {
            }
        } catch (Exception e) {
        }
        return "list";
    }
}
